package com.ruoyi.crm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.crm.domain.CrmFeeApply;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.CrmOrderProductDiscount;
import com.ruoyi.crm.service.ICrmOrderProductDiscountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商机产品折扣Controller
 *
 * @author yanwenliang
 * @date 2024-11-04
 */
@RestController
@RequestMapping("/crm/discount")
public class CrmOrderProductDiscountController extends BaseController
{
    @Autowired
    private ICrmOrderProductDiscountService crmOrderProductDiscountService;

    /**
     * 查询商机产品折扣列表
     */
//    // @PreAuthorize("@ss.hasPermi('crm:discount:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmOrderProductDiscount crmOrderProductDiscount)
    {
        startPage();
        List<CrmOrderProductDiscount> list = crmOrderProductDiscountService.selectCrmOrderProductDiscountList(crmOrderProductDiscount);
        return getDataTable(list);
    }

    /**
     * 导出商机产品折扣列表
     */
    // @PreAuthorize("@ss.hasPermi('crm:discount:export')")
    @Log(title = "商机产品折扣", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmOrderProductDiscount crmOrderProductDiscount)
    {
        List<CrmOrderProductDiscount> list = crmOrderProductDiscountService.selectCrmOrderProductDiscountList(crmOrderProductDiscount);
        ExcelUtil<CrmOrderProductDiscount> util = new ExcelUtil<CrmOrderProductDiscount>(CrmOrderProductDiscount.class);
        util.exportExcel(response, list, "商机产品折扣数据");
    }

    /**
     * 获取商机产品折扣详细信息
     */
//    // @PreAuthorize("@ss.hasPermi('crm:discount:query')")
    @GetMapping(value = "/{discountId}")
    public AjaxResult getInfo(@PathVariable("discountId") String discountId)
    {
        return success(crmOrderProductDiscountService.selectCrmOrderProductDiscountByDiscountId(discountId));
    }

    /**
     * 新增商机产品折扣
     */
    // @PreAuthorize("@ss.hasPermi('crm:discount:add')")
    @Log(title = "商机产品折扣", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmOrderProductDiscount crmOrderProductDiscount) {
        return toAjax(crmOrderProductDiscountService.insertCrmOrderProductDiscount(crmOrderProductDiscount));
    }

    /**
     * 修改商机产品折扣
     */
    // @PreAuthorize("@ss.hasPermi('crm:discount:edit')")
    @Log(title = "商机产品折扣", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmOrderProductDiscount crmOrderProductDiscount)
    {
        return toAjax(crmOrderProductDiscountService.updateCrmOrderProductDiscount(crmOrderProductDiscount));
    }

    /**
     * 删除商机产品折扣
     */
    // @PreAuthorize("@ss.hasPermi('crm:discount:remove')")
    @Log(title = "商机产品折扣", businessType = BusinessType.DELETE)
	@DeleteMapping("/{discountIds}")
    public AjaxResult remove(@PathVariable String[] discountIds)
    {
        return toAjax(crmOrderProductDiscountService.deleteCrmOrderProductDiscountByDiscountIds(discountIds));
    }

    /**
     * 审核
     *
     * @param crmOrderProductDiscount
     * @return
     */
    @PostMapping("audit")
    public AjaxResult audit(@RequestBody CrmOrderProductDiscount crmOrderProductDiscount) {
        return AjaxResult.success(crmOrderProductDiscountService.audit(crmOrderProductDiscount));
    }
}
